package org.mine.design.decorator.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.mine.design.decorator.data.RiderOrder;
import org.mine.design.decorator.data.RiderOrderPool;
import org.mine.design.decorator.service.OrderDeliveryAbstractService;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class PartOrderDeliveryAbstractServiceImpl extends OrderDeliveryAbstractService {

    @Override
    public void accept(RiderOrder riderOrder) {
        //判单当前订单是否存在于订单池
        List<RiderOrder> pool = RiderOrderPool.getPool();
        boolean belong = pool.stream()
                .anyMatch(
                        order ->
                                order.getOrderNo().equals(riderOrder.getOrderNo()) && order.getRiderId().equals(riderOrder.getRiderId())
                );
        if(belong){
            super.accept(riderOrder);
        }
    }

    /**
     * 完成
     */
    @Override
    public void complete(RiderOrder riderOrder) {
        super.complete(riderOrder);
        log.info("订单完成,获得收益 ： {}", riderOrder.getOrderAmount());
    }
}
